package com.example.larou.config;

import cn.dev33.satoken.interceptor.SaInterceptor;
import cn.dev33.satoken.router.SaRouter;
import cn.dev33.satoken.stp.StpUtil;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class SatokenFilter implements WebMvcConfigurer {
//    过滤器
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new SaInterceptor(handler->{
            SaRouter
                    .match("/**",r->System.err.println("过滤器"))
                    .notMatch("/login")
                    .notMatch("/regist")
                    .notMatch("/getAllItem")
                    .notMatch("/getMyItem")
                    .notMatch("/addItem")
                    .notMatch("/deleteItem")
                    .notMatch("/upLoad")
                    .notMatch("/addCart")
                    .notMatch("/addEmail")
                    .notMatch("/getEmail")
                    .check(r-> StpUtil.checkLogin());

        })).addPathPatterns("/**");
        WebMvcConfigurer.super.addInterceptors(registry);

    }
}
